<template>
  <div class="bigbox">
   <!-- 页面导航搜索盒子 -->
    <div class="topbox">
      <el-form ref="form" :model="forms"   label-width="60px" label-position="left">
        <el-row :gutter="20">
          <el-col :span="5">
            <el-form-item label="建筑群">
              <FilterSelect ref="jianzhuqun" :optionlist="qiyelist" :valuekey="{name:'name',value:'id'}" @changeselect="changeqiye" :defaultvalue="buildingId"></FilterSelect>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="日期">
              <el-date-picker
                size="small"
                v-model="value1"
                style="width: 100%;"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="类型">
              <el-select size="small" v-model="forms.customerType" style="width: 100%;" clearable>
                <el-option v-for="(item,index) in yomghulist" :key="index" :label="item.text" :value="item.value" class="option"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8" style="text-align: right;">
            <el-form-item label="">
              <el-button size="small" type="primary" @click="getlist()">查 询</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div> 
    <!-- 盒子主体部分 -->
    <div class="bodybox">
      <div style="display: flex;justify-content: space-between;">
        <div>销户</div>
        <div class="title">
          <TopTile  @command="command" @daochu="daochu" @shuaxin="shuaxin"></TopTile>
        </div>
      </div>
      <div class="table">
        <TableColumn
        ref="tabledata"
        :tableData="tableData" 
        :tableConfig="tableConfig" 
        :issize="issize">
        <el-table-column
            prop="address"
            label="操作"
            align="center"
            width="200">
            <template #default="{row}">
              <el-tooltip class="item" effect="dark" content="删除" placement="top">
                <i @click="shanchu(row)" class="el-icon-delete" style="color: red;cursor: pointer;margin-right: 20px;"></i>
              </el-tooltip>
            </template>
        </el-table-column>
      </TableColumn>
         <!-- 底部分页 -->
         <div class="fenye">
          <el-pagination
                background
                layout="prev, pager, next"
                :current-page.sync="pages.pageNo"
                :page-size="20"
                @current-change="getlist"
                :total="+totalCount">
          </el-pagination>
          </div>
      </div>
    </div>
  </div>
</template>

<script>
import FilterSelect from '@/components/FilterSelect'
import {gettablelistapi,postdelhuapi} from '@/api/prwpaid/user-manage/OpenAaccount'
import {getloginlistapi} from '@/api/prwpaid/file-management/Architectural-complex'
import { getzidianxialaapi } from '@/api/guidelines'
import TopTile from '@/components/TopTitle/index.vue'
import TableColumn from '@/components/Table/index.vue'
import {exportexcel} from '@/utils/excel'
export default {
  name: 'CallPoliceIndex',
  components: {
    TopTile,
    FilterSelect,
    TableColumn
  },
  data() {
    return {
      issize: 'medium',
      forms:{customerType:''},
      value1:['',''],
      yomghulist: [],
      qiyelist: [],
      tableData: [],
      tableConfig: [
      { label: '序号', type:'index' ,center:'center',width:'100'},
        { label: '建筑群名称', prop: 'buildingsName' },
        { label: '销户时间', prop: 'closeAccountDate' ,width:'180',center:'center'},
        { label: '创建人', prop: 'creatorName' ,center:'center'},
        { label: '用户编号', prop: 'customerNo' ,width:'180'},
        { label: '用户名称', prop: 'customerName' ,width:'200'},
        { label: '销户时用户余额', prop: 'closeAccountOverage' },
        { label: '联系电话', prop: 'contactPhone',center:'center' },
      ],
      totalCount:'',
      pages: {
        pageNo: 1,
        pageSize:20
      },
      buildingId:''
    };
  },

  async mounted() {
    const res = await getloginlistapi()
    this.qiyelist = res.data.list
    const localbuildingId = localStorage.getItem('buildingId')
    const isBuildIdInArray = this.qiyelist.some(item => item.id == localbuildingId);
    this.$set(this,'buildingId',isBuildIdInArray?localbuildingId:this.qiyelist[0].id)

    // 获取收费类型
    const yonghu = await getzidianxialaapi({ dictType: 'MBM_CUSTOMER_TYPE' })
    this.yomghulist = yonghu.data.list
    this.getlist()
  },

  methods: {
    // 企业下拉
    changeqiye(val) {
      localStorage.setItem('buildingId', val)
    },
    // 获取表格数据
    async getlist() {
      this.$refs.tabledata.loading=true
      const res = await gettablelistapi({
        pageNo: this.pages.pageNo - 1, pageSize: this.pages.pageSize,buildingId:this.$refs.jianzhuqun.brandId,
        startDate: this.value1[0], endDate: this.value1[1], state: '40', ...this.forms
      })
      this.tableData = res.data.list
      this.totalCount = res.data.totalCount
      this.$refs.tabledata.loading=false
    },
 // 调节表格密度
  command(val) {
      if (val === '默认') {
        this.issize = 'medium'
      } else if (val === '中等') {
        this.issize = 'small'
      } else {
        this.issize = 'mini'
      }
    },
    // 导出
    daochu() {
      exportexcel('mbm-microservice-biz/mbm/customer/exportExcel',
        { startDate: this.value1[0], endDate: this.value1[1], state: '01', ...this.forms },
        '销户信息')
    },
    // 刷新列表
    shuaxin() {
      this.$message.success('列表刷新成功')
      this.getlist()
    },
    // 删除
    shanchu(val) {
      this.$confirm('此操作将永久删除该档案, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(async () => {
          await postdelhuapi({ id: val.id })
          this.getlist()
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
      
    }
  },
};
</script>

<style lang="scss" scoped>
// *{
//   margin: 0;
//   padding: 0;
//   box-sizing: border-box;
// }
.option{
  margin-left: 10px;
}
.bigbox{
  height: 100%;
  padding: 10px;
  .topbox{
    height: 80px;
    padding: 20px;
    background-color: #fff;
    margin-bottom: 10px;
    span{
      margin-right: 15px;
    }
    .button{
      width: 60px;
      height: 30px;
      background-color: #1a90fe;
      color: #fff;
      border-radius: 3px;
      border: none;
    }
  }
  .bodybox{
    height: calc(100% - 90px);
    padding: 20px;
    background-color: #fff;
    .title{
      margin-bottom: 10px;
    }
    .table{
      height: 90%;
      .fenye{
        margin-top: 10px;
        text-align: right;
      }
    }
  }
}
</style>